package com.pt.pok.string;

import com.pt.pok.*;
import com.pt.pok.model.ClassIds;

/**
 * @author Andrey.Panfilov@playtech.com
 */
public class StringConverterFactory
    implements ConverterFactory<String> {

    public ProtocolConverter<String> getProtocolConverter() {
        Dispatcher<String> dispatcher = new StringDispatcher();

        initializeHandlers(dispatcher);
        initializeMarshallers(dispatcher);

        return new StringProtocolConverter(dispatcher);
    }

    private void initializeMarshallers(Dispatcher<String> dispatcher) {
        ProtocolMarshaller<String> loginCommandMarshaller = new LoginCommandMarshaller();

        dispatcher.registerMarshaller(ClassIds.LOGIN_REQUEST.getId(), loginCommandMarshaller);
    }

    private void initializeHandlers(Dispatcher<String> dispatcher) {
        CommandHandler<String> loginRequestCommandHandler = new LoginRequestCommandHandler();

        dispatcher.registerHandler(ClassIds.LOGIN_REQUEST.getId(), loginRequestCommandHandler);
    }

}
